package com.bah.tract.action;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.core.Manager;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.NotLoggedInException;

@Scope(ScopeType.APPLICATION)
@BypassInterceptors
@Name("org.jboss.seam.navigation.pages")
@Install(precedence = Install.DEPLOYMENT, classDependencies = "javax.faces.context.FacesContext")
@Startup
public class Pages extends org.jboss.seam.navigation.Pages {

	public void redirectToLoginView() {
		notLoggedIn();
		StatusMessages.instance().clearGlobalMessages();
		// Ensure that we haven't been authenticated as a result of the
		// org.jboss.seam.security.notLoggedIn event
		if (!Identity.instance().isLoggedIn()) {
			String loginViewId = getLoginViewId();
			if (loginViewId == null) {
				throw new NotLoggedInException();
			} else {
				Manager.instance().redirect(loginViewId);
			}
		}
	}
}